package order.interfaces.controller;

import order.application.service.AddressService;
import order.domain.model.Address;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping
    public ResponseEntity<Void> save(@RequestBody Address address) {
        addressService.save(address);
        return ResponseEntity.ok().build();
    }

    @GetMapping("/order/{orderId}")
    public ResponseEntity<Address> getByOrderId(@PathVariable Long orderId) {
        return ResponseEntity.ok(addressService.getByOrderId(orderId));
    }
}